﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Avatar.Management;
using Avatar.Common;
using AvatarHelper;
using System.Data.Linq;
using System.Linq;

public partial class Admin_ConfigSet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (var _adc = DBHelper.GetDataContext())
            {
                var _config = _adc.SiteConfig.FirstOrDefault();
                if (_config != null)
                {
                    txt_Description.Value = _config.Description.Trim();
                    txt_Email.Text = _config.Email.Trim();
                    txt_ID.Value = _config.ID.ToString();
                    txt_KeyWord.Value = _config.KeyWord.Trim();
                    txt_SiteName.Text = _config.SiteName;
                    txt_Title.Text = _config.Title.Trim();
                    txt_Url.Text = _config.Url;
                    txt_LogoURL.Text = _config.LogoUrl;
                    txt_Footer.Value = _config.Footer;
                    txt_About.Value = _config.About;
                    txt_Charges.Value = _config.Charges;
                    txt_ContactUs.Value = _config.ContactUs;
                    txt_ServiceCenter.Value = _config.ServiceCenter;
                    txt_Statement.Value = _config.Statement;
                }
            }
        }
    }

    protected void btn_Save_Click(object sender, EventArgs e)
    {
        try
        {
            SiteInformationManager.Save(
                string.IsNullOrEmpty(txt_ID.Value) ? 0 : Convert.ToInt32(txt_ID.Value),
                txt_Description.Value,
                txt_Email.Text,
                txt_KeyWord.Value,
                txt_SiteName.Text,
                txt_Title.Text,
                txt_Url.Text,
                txt_LogoURL.Text,
                txt_Footer.Value,
                txt_Statement.Value,
                txt_ServiceCenter.Value,
                txt_ContactUs.Value,
                txt_Charges.Value,
                txt_About.Value);

            Response.Redirect(Request.Url.ToString());
        }
        catch(Exception _e)
        {
            Helper.ShowMassage(_e.Message);
        }
    }
}